package utils;

public class FpsHandler {

	private long _lastFpsTime = 0;
	private int _fps;//计数器
	private int _displayFps;
	private long _seconds = 1000000000;//1秒

	//接受一个updateTime参数，单位为纳秒，累加到_lastFpsTime上；_fps是一个计数器
	//如果_lastFpsTime >= _seconds条件满足说明刚刚过去了1秒，重置_lastFpsTime，_fps
	//返回_displayFps；该值不是0就是_fps（即1秒钟的帧数）
	public int getFps(long updateTime){
		_lastFpsTime += updateTime;
		_fps++;
		if (_lastFpsTime >= _seconds)
		{
			_displayFps = _fps;
		   _lastFpsTime = 0;
		   _fps = 0;
		}
		return _displayFps;
	}

}
